package cn.saltice.idempotence.idem.utils;

import cn.saltice.idempotence.idem.aspect.Idempotent;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;

import java.lang.reflect.Method;

/**
 * @program: IoT-Plat
 * @description:
 * @author: Mr.Liu
 * @create: 2020-05-19 22:45
 **/
public class IdempotentMethodUtils {
    public static Method getCompensableMethod(ProceedingJoinPoint pjp) {
        Method method = ((MethodSignature) (pjp.getSignature())).getMethod();

        if (method.getAnnotation(Idempotent.class) == null) {
            try {
                method = pjp.getTarget().getClass().getMethod(method.getName(), method.getParameterTypes());
            } catch (NoSuchMethodException e) {
                return null;
            }
        }
        return method;
    }
}
